abstract class Person { private String name,city; public Person(String nm,String ct) { name=nm; city=ct; } public void showData() { System.out.println("name is "+name); System.out.println("City is "+city); } } class Student extends Person { private int rollno; public Student(int rn,String nm,String ct) { super(nm,ct); rollno=rn; } public void showData() { System.out.println("rollno is "+rollno); super.showData(); } } class demo { public static void main(String args[]) { Person a=new Person("Nitin","Nagpur"); a.showData(); Student b=new Student(4117 ,"amit jain","Amravati"); b.showData(); } }
error: Person is abstract; cannot be instantiated Person a=new Person("Nitin","Nagpur"); ^
abstract class Person { private String name,city; public Person(String nm,String ct) { name=nm; city=ct; } public abstract void showData(); } class Student extends Person { private int rollno; public Student(int rn,String nm, String ct) { super(nm,ct); rollno=rn; } public void showData() { System.out.println("rollno is "+rollno); System.out.println("name is "+name); System.out.println("city is "+city); } } class demo { public static void main(String args[]) { Student a=new Student(4117,"amit jain","Amravati"); a.showData(); } }
rollno is 4117 name is amit jain city is Amravati